<template>
	<view>
		<view class="fixNickTit">设置昵称</view>
		<view class="inpWrap">
			<input class="inp" type="text" placeholder="请输入昵称" maxlength="8" v-model="nickName" placeholder-class="holdInp">
			<view class="tips">8个字符内,可为汉字、或字母和数字组合,不支持空格和特殊符号</view>
		</view>
		<button class="comBtn" :disabled="isDisabledFlag" @tap="saveNickName">保存</button>
	</view>
</template>

<script>
	import { upNickName } from '@/api/mine/index'
	export default {
		data(){
			return{
				nickName:'',
				isDisabledFlag:false
			}
		},
		methods:{
			saveNickName(){
				if(this.nickName == ''){
					this.util.showToast('用户昵称不能为空');
				}else{
					var field = {netName:this.nickName};
					this.isDisabledFlag = true;
					uni.showLoading({
						title: '修改中...',
						mask: true
					});
					upNickName(field).then(res=>{
						this.util.showToastSuc('修改成功');
						let pages = getCurrentPages();
						let prevPage = pages[pages.length - 2];
						prevPage.$vm.nickName = this.nickName;
						if(!uni.getStorageSync('IMRefuseNum')){//IM未欠费
							//更新即时通讯服务器上的昵称
							uni.$TUIKit.updateMyProfile({nick: this.nickName}).then(res => {}).catch(err=>{});
						}
						setTimeout(()=>{
							uni.navigateBack({
								delta:1
							})
						},1500);
					}).catch(err=>{
						this.isDisabledFlag = false;
					});
				}
			}
		}
	}
</script>

<style lang='scss'>
	@import '@/static/scss/setNickName.scss';
</style>